<template>
	<div class="common_title">
		<img src="@/assets/images/wechat/student/consultadd/conscreate_user.png">
		<p>咨询用户信息</p>
	</div>
	<div class="common_info">
		<label>用户姓名</label>
		<div>{{studentData.name}}</div>
	</div>
	<div class="common_line"></div>
	<div class="common_info">
		<label>手机号</label>
		<div>{{studentData.mobilePhone}}</div>
	</div>
	<div class="common_title">
		<img src="@/assets/images/wechat/student/consultadd/conscreate_admin.png">
		<p>受理人信息</p>
	</div>
	<div class="common_info">
		<label>受理人姓名</label>
		<div>{{lawyerData.name}}</div>
	</div>
	<div class="common_title">
		<img src="@/assets/images/wechat/student/consultadd/conscreate_consult.png">
		<p>咨询详情信息</p>
	</div>
	<div class="common_info">
		<label>咨询类型</label>
		<select v-model="consultTypeIndex">
			<option v-for="(item,index) in consultTypeList" :key="index" :value="index" >{{item.title}}</option>
		</select>
	</div>
	<div class="common_info">
		<label>咨询描述</label>
		<input type="text" placeholder="必填项否则无法发起咨询" v-model="consultData.description">
	</div>
	
	<div class="footer">
		<a v-if="studentData.mobilePhone" href="javascript:;" @click="ajaxInsertConsult" class="footer_success">提交工单</a>
		<router-link v-else class="footer_fail" :to="{path:'studentinfo'}">绑定手机</router-link>
	</div>
</template>

<script>
//引入js	
import router from '@/router/index'
import { studentFindStudentById } from '@/api/student'
import { studentFindLawyerById } from '@/api/lawyer'
import { studentSelectConsultType } from '@/api/consulttype'
import { studentInsertConsultLawyer } from '@/api/consultlawyer'
	
export default {
	components: {
	},
    data(){
		return {
			ajaxFlag:true,//监控ajax请求，避免多次请求
			
			studentData:{},
			lawyerData:{},
			consultTypeList:[],
			consultTypeIndex:0,
			pageData:{
				pageNo:1,
				pageSize:20,
				total:0
			},
			consultData:{
				description:''
			}
		}
    },
    created:async function(){
		
		var ajaxData = {}
		var resultData = await studentFindStudentById(ajaxData)
		if(resultData.code==200){
			this.studentData=resultData.data
		}
		
		ajaxData = {}
		ajaxData.id=this.$route.query.lawyerId;
		resultData = await studentFindLawyerById(ajaxData)
		if(resultData.code==200){
			this.lawyerData=resultData.data;
		}
		
		ajaxData={}
		ajaxData.pageNo=this.pageData.pageNo
		ajaxData.pageSize=this.pageData.pageSize
		resultData = await studentSelectConsultType(ajaxData)
		if(resultData.code==200){
			this.consultTypeList=resultData.data.consultTypeList
		}
  	},
  	beforeMount: function() {
		
    },
  	mounted: function () {
  		
  	},
  	methods:{
  		ajaxInsertConsult:async function(){
			if(!this.studentData.mobilePhone){
				alert("未绑定手机号");
				return 0;
			}
			if(!this.lawyerData.id){
				alert("律师信息获取失败");
				return 0;
			}
			if(!this.consultData.description||this.consultData.description.length>=100){
				alert("问题描述内容必填且长度不超过100");
				return 0;
			}
			var ajaxData={}
			ajaxData.lawyerId=this.lawyerData.id
			ajaxData.consultTypeId=this.consultTypeList[this.consultTypeIndex].id
			ajaxData.riskLevel=this.consultTypeList[this.consultTypeIndex].level
			ajaxData.description=this.consultData.description
			
			var resultData = await studentInsertConsultLawyer(ajaxData)
			if (resultData.code == 200) {
				alert(resultData.msg)
				router.replace({
					path: '/wechatstudent/consultlist'
				});
				return 0;
			} else {
				alert("当前存在未咨询完的工单")
				router.replace({
					path: '/wechatstudent/consultlist'
				});
				return 0;
			}
		}
  	}
}
</script>

<style lang="scss" scoped>
.common_title{ width:100%; height:36px; overflow:hidden;}
.common_title>img{ width:24px; height:24px;  float:left; margin-left:10px; margin-top:6px;}
.common_title>p{ float:left; margin-left:10px; line-height:36px; color:#0054bc}

.common_info{ width:100%; overflow:hidden; background:#FFF; color:#868686}
.common_info>label{ width:30%; float:left; line-height:40px; text-align:right}
.common_info>div{ width:60%; float:left; line-height:40px; text-indent:10px; color:#666666}
.common_info>select{font-size:16px;width:60%; float:left; height:40px;border:none; text-indent:6px; outline:none;color:#666666}
.common_info>input{font-size:16px;width:60%; float:left; height:40px; border:none; margin-left:10px; outline:none; color:#666666}
.common_line{ width:100%; height:1px; background:#f1f1f1; float:left;}

.footer{ width:100%; overflow:hidden; position:fixed; left:0; bottom:0;}
.footer>a{ width:100%; display:block; line-height:50px; text-align:center; color:#FFF;}
.footer_success{ background:#0054bc;}
.footer_fail{ background:#ff5100}
</style>
